import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:flutter_kx_crypto/flutter_kx_crypto.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String _encry = '未操作';
  String _decry = '未操作';

  @override
  void initState() {
    super.initState();
    initPlatformState();
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  Future<void> initPlatformState() async {
    String platformVersion;

    // Platform messages may fail, so we use a try/catch PlatformException.
    try {
      platformVersion = await FlutterKxCrypto.platformVersion;
    } on PlatformException {
      platformVersion = 'Failed to get platform version.';
    }

    if (!mounted) return;
    setState(() {
      _platformVersion = platformVersion;
    });
  }


  void encrydata() async {
    _encry = await FlutterKxCrypto.encrypt3DES('NWY0ZTNiMGEtYjAyNC00M2Rh', 'hello');
    setState(() {

    });
  }

  void _decrydata() async {
    _decry = await FlutterKxCrypto.decrypt3DES('NTMyMGM5NDQtY2ZkNy00MzVj', 'hWn\/PXOrathHkzVTUwru1+sjBHDZZZkRf3UxH9g\/H1r98qsPrNuILYlQjgrPAHsfnwFKVIumS2hewsZTvt0M7Yq4yQkoqvmFx7MZCTgQ2EzAxEUgRi3GYy25R+tgD02TXtPUqHaFyGUr4Jdnmvzs9UVf\/AK0CrrTlkHstfFYbKjKnojKl3v1J+KV\/CQwodpRuoP1sZBFg3i9pw39EiMjZeZUG4PziXG71xBeOonVC40mYir5OpmnJ2bmVNXwOBv0L3g6ZNsuQSAi8032xspPRkME7oWCNOjUT7u9X15WYXUUpZ\/eVeFf4g4wCfmG8sIX6oatFoQuuENEP0laCaSB87QDVHL5bptFYDhgoU1l0IR9sxaK6wA8isO4x4PyjY15+9rlILDFCnswrbcvS5NWclCA4htbl1rJUfTE4ZvCchGouM7K8Fb2+1ywF9ejKqNUCB5GjHpTXYaerNs35xDhcK0FET\/MT4Pk5y1LZBo938lcKUL34bvGzQv7di\/cZ6g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6VsFkD9LUIDiG1uXWslR9MThm8JyEai4zsrwVvb7XLAX16Mqo1S16lIqJYu\/cwj2B4ucNCUtIKTGYNvpHpHlfKb2n002Qw==');
    setState(() {

    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Column(
            children: <Widget>[
              Text('Running on: $_platformVersion\n'),
              Text('Encryt: $_encry\n'),
              Text('decryt: $_decry\n'),
              FlatButton(
                onPressed: () {
                  encrydata();
                },
                child: Text(
                  '加密',
                ),
              ),
              FlatButton(
                onPressed: () {
                  _decrydata();
                },
                child: Text(
                  '解密',
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }


}
